﻿<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
       
        //System.Collections.Generic.List<FileGarbishCollection> lstNew = new System.Collections.Generic.List<FileGarbishCollection>();
        //lstNew.Add(new FileGarbishCollection(ConnectionStrings.LMS, "Courses", "Path", Server.MapPath("./CoursesFiles")));
        //lstNew.Add(new FileGarbishCollection(ConnectionStrings.LMS, "Courses", "Path", Server.MapPath("./CourseFiles")));
        //FileGarbishCollection.startClearThread(lstNew);
        
        
        // Code that runs on application startup
        Application["CurrentCount"] = (long)0;

        //try
        //{
        //    Application["emailData"] = GlobalVars.getEmailData();
        //}
        //catch
        //{
        //}

    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    {

        try
        {
            
            
            Exception ex = Server.GetLastError();

            if (!ex.Message.Equals("File does not exist."))
            {

                DatabaseComponent.LmsErrorsDB objLmsErrorDB = new DatabaseComponent.LmsErrorsDB(ConnectionStrings.LMS);
                DatabaseComponent.LmsErrors objLmsError = new DatabaseComponent.LmsErrors();
                if (ex.Data != null)
                    objLmsError.ErrData = ex.Data.ToString();
                objLmsError.ErrMessage = ex.Message;
                if (sender != null)
                    objLmsError.ErrSender = sender.ToString();
                objLmsError.ErrStackTrace = ex.StackTrace;
                objLmsError.ErrToString = ex.ToString();

                objLmsErrorDB.Insert(objLmsError);
            }
           
            
            
        }
        catch
        {
        }
        
        
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {

        if (Application["CurrentCount"] == null)
            Application["CurrentCount"] = (long)0;
               
        try
        {
            DatabaseComponent.HistoryVisitsDB objHistoryVisitsDB = new DatabaseComponent.HistoryVisitsDB(ConnectionStrings.LMS);

            DatabaseComponent.HistoryVisits objHistoryVisits = new DatabaseComponent.HistoryVisits();
            objHistoryVisits.NoOfMembers = DatabaseComponent.HistoryVisits.MyCount + 1;

            objHistoryVisitsDB.Insert(objHistoryVisits);

            Application.Lock();

            Application["CurrentCount"] = long.Parse(Application["CurrentCount"].ToString()) + 1;

            long lngNew = (long)Application["CurrentCount"];
            DateTime dtCurrent = DateTime.Now;
            
            Application.UnLock();


            if (lngNew > DatabaseComponent.MaxVisitsDate.objMax.MaxConcurrenceNumber)
            {
                DatabaseComponent.MaxVisitsDateDB objMaxDB = new DatabaseComponent.MaxVisitsDateDB(ConnectionStrings.LMS);
                DatabaseComponent.MaxVisitsDate obj = new DatabaseComponent.MaxVisitsDate();
                obj.MaxConcurrenceNumber = lngNew;
                obj.CurrentDate = dtCurrent;

                objMaxDB.Insert(obj);
            }
            
            
        }
        catch
        {
        }
            
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e) 
    {
        try
        {
           

            Application.Lock();

            Application["CurrentCount"] = long.Parse(Application["CurrentCount"].ToString()) - 1;

            Application.UnLock();
        }
        catch
        {
        }
        
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }
       
</script>
